export default [
  {
    version: 1,
    script: `
      CREATE TABLE context
      (
        id        INTEGER NOT NULL CONSTRAINT context_pk PRIMARY KEY AUTOINCREMENT,
        key       TEXT,
        val       TEXT
      );

      INSERT INTO context (key, val) VALUES ('db_version', '1');

      CREATE TABLE f2f_model
      (
        id         INTEGER CONSTRAINT f2f_model_pk PRIMARY KEY AUTOINCREMENT,
        name       TEXT,
        video_path TEXT,
        audio_path TEXT,
        voice_id   INTEGER,
        created_at INTEGER
      );

      CREATE TABLE video
      (
        id             INTEGER CONSTRAINT video_result_pk PRIMARY KEY AUTOINCREMENT,
        file_path      TEXT,
        status         TEXT,
        message        TEXT,
        model_id       INTEGER,
        audio_path     TEXT,
        param          INTEGER,
        code           TEXT,
        created_at     INTEGER,
        progress       INTEGER DEFAULT 0,
        name           TEXT,
        duration       INTEGER,
        text_content   TEXT
      );
    `
  },
  {
    version: 2,
    script: `
      CREATE TABLE voice
      (
        id                   INTEGER CONSTRAINT tts_train_task_pk PRIMARY KEY AUTOINCREMENT,
        origin_audio_path    TEXT,
        lang                 TEXT,
        asr_format_audio_url TEXT,
        reference_audio_text TEXT,
        created_at           INTEGER
      );
    `
  },
  {
    version: 3,
    script: `
      ALTER TABLE video
        ADD COLUMN voice_id INTEGER;
      ALTER TABLE video
        ADD COLUMN is_common TEXT;
    `
  },
  {
    version: 4,
    script: `
      CREATE TABLE api_keys
      (
        id          INTEGER NOT NULL CONSTRAINT api_keys_pk PRIMARY KEY AUTOINCREMENT,
        name        TEXT,
        key         TEXT,
        enabled     INTEGER DEFAULT 0,
        created_at  INTEGER,
        updated_at  INTEGER,
        description TEXT
      );
    `
  },
  {
    version: 5,
    script: `
      CREATE TABLE IF NOT EXISTS server_config
      (
        id                 INTEGER NOT NULL CONSTRAINT server_config_pk PRIMARY KEY,
        base_url           TEXT    NOT NULL,
        base_url_with_port TEXT    NOT NULL,
        face2face          TEXT    NOT NULL,
        tts                TEXT    NOT NULL,
        kpop_baseUrl       TEXT    NOT NULL,
        created_at         INTEGER,
        updated_at         INTEGER
      );

      -- 初始化默认数据
      INSERT OR IGNORE INTO server_config (id, base_url, base_url_with_port, face2face, tts, kpop_baseUrl, created_at, updated_at)
      VALUES (1, 'http://192.168.0.151', 'http://192.168.0.151:2000', '8383', '18180', 'http://192.168.0.151', STRFTIME('%s', 'now') * 1000, STRFTIME('%s', 'now') * 1000);
    `
  },
  {
    version: 6,
    script: `
      CREATE TABLE IF NOT EXISTS proxy_config
      (
        id         INTEGER NOT NULL CONSTRAINT proxy_config_pk PRIMARY KEY,
        proxy_url  TEXT    NOT NULL,
        enabled    INTEGER DEFAULT 0,
        created_at INTEGER,
        updated_at INTEGER
      );

      -- 初始化默认数据
      INSERT OR IGNORE INTO proxy_config (id, proxy_url, enabled, created_at, updated_at)
      VALUES (1, 'https://804b7fa7dfd40fbd0cdc54b0a0f5e5f7.api-forwards.com/v1', 0, STRFTIME('%s', 'now') * 1000, STRFTIME('%s', 'now') * 1000);
    `
  },
  {
    version: 7,
    script: `
      CREATE TABLE IF NOT EXISTS tts_history
      (
        id            INTEGER NOT NULL CONSTRAINT tts_history_pk PRIMARY KEY AUTOINCREMENT,
        history_id    INTEGER,
        name          TEXT,
        text          TEXT,
        name_origin   TEXT,
        text_origin   TEXT,
        audio_path    TEXT,
        duration      REAL,
        model         TEXT,
        voice         TEXT,
        language      TEXT,
        instructions  TEXT,
        caption_path  TEXT,
        caption_status TEXT DEFAULT 'none',
        caption_error TEXT,
        caption_format TEXT DEFAULT 'srt',
        created_at    INTEGER
      );

      CREATE INDEX IF NOT EXISTS tts_history_created_at_index
        ON tts_history (created_at DESC);
    `
  },
  {
    version: 8,
    script: `
      CREATE TABLE IF NOT EXISTS category
      (
        id           INTEGER NOT NULL CONSTRAINT category_pk PRIMARY KEY AUTOINCREMENT,
        name         TEXT    NOT NULL,
        parent_id    INTEGER NOT NULL DEFAULT 0,
        level        INTEGER NOT NULL,
        sort         INTEGER NOT NULL DEFAULT 0,
        created_at   INTEGER,
        updated_at   INTEGER
      );

      CREATE INDEX IF NOT EXISTS category_parent_id_index
        ON category (parent_id);

      ALTER TABLE video ADD COLUMN primary_category_id     INTEGER;
      ALTER TABLE video ADD COLUMN secondary_category_id   INTEGER;
      ALTER TABLE video ADD COLUMN tertiary_category_id    INTEGER;
      ALTER TABLE video ADD COLUMN primary_category_name   TEXT;
      ALTER TABLE video ADD COLUMN secondary_category_name TEXT;
      ALTER TABLE video ADD COLUMN tertiary_category_name  TEXT;
      ALTER TABLE video ADD COLUMN file_md5                TEXT;
      ALTER TABLE video ADD COLUMN file_size               INTEGER;
      ALTER TABLE video ADD COLUMN thumbnail_path          TEXT;
      ALTER TABLE video ADD COLUMN description             TEXT;
      ALTER TABLE video ADD COLUMN caption_path             TEXT;
      ALTER TABLE video ADD COLUMN with_caption             INTEGER DEFAULT 0;
      ALTER TABLE video ADD COLUMN video_with_caption_path   TEXT;

      CREATE INDEX IF NOT EXISTS video_categories_index
        ON video (primary_category_id, secondary_category_id, tertiary_category_id);

      CREATE UNIQUE INDEX IF NOT EXISTS video_file_md5_index
        ON video (file_md5);
    `
  },
  {
    version: 9,
    script: `
      CREATE TABLE asset_paths
      (
        id          INTEGER NOT NULL CONSTRAINT asset_paths_pk PRIMARY KEY AUTOINCREMENT,
        path_key    TEXT    NOT NULL,
        path_value  TEXT    NOT NULL,
        description TEXT,
        enabled     INTEGER DEFAULT 1,
        created_at  INTEGER,
        updated_at  INTEGER
      );

      -- 预设默认路径
      INSERT INTO asset_paths (path_key, path_value, description, enabled, created_at, updated_at)
      VALUES
        ('model', 'http://192.168.0.151:9001/face2face/temp', '模特视频路径', 1, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
        ('ttsProduct', 'http://192.168.0.151:9001/face2face/temp', 'TTS产物路径', 1, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
        ('ttsRoot', 'http://192.168.0.151:9001/voice/data', 'TTS服务根目录', 1, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
        ('ttsTrain', 'http://192.168.0.151:9001/voice/data/origin_audio', 'TTS训练产物路径', 1, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP);
    `
  }
]
